package com.WaVel.service.impl;

import com.Emplyment.entity.InterView;
import com.Emplyment.vo.CommentVo;
import com.Emplyment.vo.InterViewVo;
import com.WaVel.mapper.InterviewDiscussionMapper;
import com.WaVel.service.InterviewDiscussionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class InterviewDiscussionServiceImpl implements InterviewDiscussionService {

    @Autowired
    private InterviewDiscussionMapper interviewDiscussionMapper;

    /**
     * 获取面经文章
     * @param category
     * @return
     */
    @Override
    public List<InterViewVo> getInterviewArticles(String category) {
        List<InterViewVo> list = new ArrayList<>();
        //获取所有的面经文章
        List<InterViewVo> interviewArticles = interviewDiscussionMapper.getInterviewArticles(category);
        //获取所有的评论信息、并添加到文章中
        for (InterViewVo interViewVo : interviewArticles) {
            int interviewId = interViewVo.getInterviewId();
            List<CommentVo> comments = interviewDiscussionMapper.getComments(interviewId);
            interViewVo.setComments(comments);
            list.add(interViewVo);
        }
        log.info("获取面经列表:{}", list);
        return list;
    }

    @Override
    public void deleteInterviewComment(int id) {
        interviewDiscussionMapper.deleteInterviewComment(id);
    }

    @Override
    public void deleteInterviewArticle(int id) {
        //先删除对应的面经文章
        interviewDiscussionMapper.deleteInterviewArticle(id);
        //完成后要删除对应的文章评论信息
        interviewDiscussionMapper.deleteComments(id);
    }
}
